home *** CD-ROM | disk | FTP | other *** search
/ Sky at Night 2007 June / SAN CD 6-2007 CD-ROM 25.iso / pc / Software / AstroGrav_Win / Java / jre1.6.0 / lib / rt.jar / java / io / RandomAccessFile.class (.txt) < prev    next >
Encoding:
Java Class File  |  2006-11-29  |  5.4 KB  |  349 lines

  1. package java.io;
  2.  
  3. import java.nio.channels.FileChannel;
  4. import sun.nio.ch.FileChannelImpl;
  5.  
  6. public class RandomAccessFile implements DataOutput, DataInput, Closeable {
  7.    // $FF: renamed from: fd java.io.FileDescriptor
  8.    private FileDescriptor field_0;
  9.    private FileChannel channel;
  10.    // $FF: renamed from: rw boolean
  11.    private boolean field_1;
  12.    private static final int O_RDONLY = 1;
  13.    private static final int O_RDWR = 2;
  14.    private static final int O_SYNC = 4;
  15.    private static final int O_DSYNC = 8;
  16.  
  17.    public RandomAccessFile(String var1, String var2) throws FileNotFoundException {
  18.       this(var1 != null ? new File(var1) : null, var2);
  19.    }
  20.  
  21.    public RandomAccessFile(File var1, String var2) throws FileNotFoundException {
  22.       this.channel = null;
  23.       String var3 = var1 != null ? var1.getPath() : null;
  24.       int var4 = -1;
  25.       if (var2.equals("r")) {
  26.          var4 = 1;
  27.       } else if (var2.startsWith("rw")) {
  28.          var4 = 2;
  29.          this.field_1 = true;
  30.          if (var2.length() > 2) {
  31.             if (var2.equals("rws")) {
  32.                var4 |= 4;
  33.             } else if (var2.equals("rwd")) {
  34.                var4 |= 8;
  35.             } else {
  36.                var4 = -1;
  37.             }
  38.          }
  39.       }
  40.  
  41.       if (var4 < 0) {
  42.          throw new IllegalArgumentException("Illegal mode \"" + var2 + "\" must be one of " + "\"r\", \"rw\", \"rws\"," + " or \"rwd\"");
  43.       } else {
  44.          SecurityManager var5 = System.getSecurityManager();
  45.          if (var5 != null) {
  46.             var5.checkRead(var3);
  47.             if (this.field_1) {
  48.                var5.checkWrite(var3);
  49.             }
  50.          }
  51.  
  52.          if (var3 == null) {
  53.             throw new NullPointerException();
  54.          } else {
  55.             this.field_0 = new FileDescriptor();
  56.             this.open(var3, var4);
  57.          }
  58.       }
  59.    }
  60.  
  61.    public final FileDescriptor getFD() throws IOException {
  62.       if (this.field_0 != null) {
  63.          return this.field_0;
  64.       } else {
  65.          throw new IOException();
  66.       }
  67.    }
  68.  
  69.    public final FileChannel getChannel() {
  70.       synchronized(this) {
  71.          if (this.channel == null) {
  72.             this.channel = FileChannelImpl.open(this.field_0, true, this.field_1, this);
  73.          }
  74.  
  75.          return this.channel;
  76.       }
  77.    }
  78.  
  79.    private native void open(String var1, int var2) throws FileNotFoundException;
  80.  
  81.    public native int read() throws IOException;
  82.  
  83.    private native int readBytes(byte[] var1, int var2, int var3) throws IOException;
  84.  
  85.    public int read(byte[] var1, int var2, int var3) throws IOException {
  86.       return this.readBytes(var1, var2, var3);
  87.    }
  88.  
  89.    public int read(byte[] var1) throws IOException {
  90.       return this.readBytes(var1, 0, var1.length);
  91.    }
  92.  
  93.    public final void readFully(byte[] var1) throws IOException {
  94.       this.readFully(var1, 0, var1.length);
  95.    }
  96.  
  97.    public final void readFully(byte[] var1, int var2, int var3) throws IOException {
  98.       int var4 = 0;
  99.  
  100.       do {
  101.          int var5 = this.read(var1, var2 + var4, var3 - var4);
  102.          if (var5 < 0) {
  103.             throw new EOFException();
  104.          }
  105.  
  106.          var4 += var5;
  107.       } while(var4 < var3);
  108.  
  109.    }
  110.  
  111.    public int skipBytes(int var1) throws IOException {
  112.       if (var1 <= 0) {
  113.          return 0;
  114.       } else {
  115.          long var2 = this.getFilePointer();
  116.          long var4 = this.length();
  117.          long var6 = var2 + (long)var1;
  118.          if (var6 > var4) {
  119.             var6 = var4;
  120.          }
  121.  
  122.          this.seek(var6);
  123.          return (int)(var6 - var2);
  124.       }
  125.    }
  126.  
  127.    public native void write(int var1) throws IOException;
  128.  
  129.    private native void writeBytes(byte[] var1, int var2, int var3) throws IOException;
  130.  
  131.    public void write(byte[] var1) throws IOException {
  132.       this.writeBytes(var1, 0, var1.length);
  133.    }
  134.  
  135.    public void write(byte[] var1, int var2, int var3) throws IOException {
  136.       this.writeBytes(var1, var2, var3);
  137.    }
  138.  
  139.    public native long getFilePointer() throws IOException;
  140.  
  141.    public native void seek(long var1) throws IOException;
  142.  
  143.    public native long length() throws IOException;
  144.  
  145.    public native void setLength(long var1) throws IOException;
  146.  
  147.    public void close() throws IOException {
  148.       if (this.channel != null) {
  149.          this.channel.close();
  150.       }
  151.  
  152.       this.close0();
  153.    }
  154.  
  155.    public final boolean readBoolean() throws IOException {
  156.       int var1 = this.read();
  157.       if (var1 < 0) {
  158.          throw new EOFException();
  159.       } else {
  160.          return var1 != 0;
  161.       }
  162.    }
  163.  
  164.    public final byte readByte() throws IOException {
  165.       int var1 = this.read();
  166.       if (var1 < 0) {
  167.          throw new EOFException();
  168.       } else {
  169.          return (byte)var1;
  170.       }
  171.    }
  172.  
  173.    public final int readUnsignedByte() throws IOException {
  174.       int var1 = this.read();
  175.       if (var1 < 0) {
  176.          throw new EOFException();
  177.       } else {
  178.          return var1;
  179.       }
  180.    }
  181.  
  182.    public final short readShort() throws IOException {
  183.       int var1 = this.read();
  184.       int var2 = this.read();
  185.       if ((var1 | var2) < 0) {
  186.          throw new EOFException();
  187.       } else {
  188.          return (short)((var1 << 8) + (var2 << 0));
  189.       }
  190.    }
  191.  
  192.    public final int readUnsignedShort() throws IOException {
  193.       int var1 = this.read();
  194.       int var2 = this.read();
  195.       if ((var1 | var2) < 0) {
  196.          throw new EOFException();
  197.       } else {
  198.          return (var1 << 8) + (var2 << 0);
  199.       }
  200.    }
  201.  
  202.    public final char readChar() throws IOException {
  203.       int var1 = this.read();
  204.       int var2 = this.read();
  205.       if ((var1 | var2) < 0) {
  206.          throw new EOFException();
  207.       } else {
  208.          return (char)((var1 << 8) + (var2 << 0));
  209.       }
  210.    }
  211.  
  212.    public final int readInt() throws IOException {
  213.       int var1 = this.read();
  214.       int var2 = this.read();
  215.       int var3 = this.read();
  216.       int var4 = this.read();
  217.       if ((var1 | var2 | var3 | var4) < 0) {
  218.          throw new EOFException();
  219.       } else {
  220.          return (var1 << 24) + (var2 << 16) + (var3 << 8) + (var4 << 0);
  221.       }
  222.    }
  223.  
  224.    public final long readLong() throws IOException {
  225.       return ((long)this.readInt() << 32) + ((long)this.readInt() & 4294967295L);
  226.    }
  227.  
  228.    public final float readFloat() throws IOException {
  229.       return Float.intBitsToFloat(this.readInt());
  230.    }
  231.  
  232.    public final double readDouble() throws IOException {
  233.       return Double.longBitsToDouble(this.readLong());
  234.    }
  235.  
  236.    public final String readLine() throws IOException {
  237.       StringBuffer var1 = new StringBuffer();
  238.       int var2 = -1;
  239.       boolean var3 = false;
  240.  
  241.       while(!var3) {
  242.          switch (var2 = this.read()) {
  243.             case -1:
  244.             case 10:
  245.                var3 = true;
  246.                break;
  247.             case 13:
  248.                var3 = true;
  249.                long var4 = this.getFilePointer();
  250.                if (this.read() != 10) {
  251.                   this.seek(var4);
  252.                }
  253.                break;
  254.             default:
  255.                var1.append((char)var2);
  256.          }
  257.       }
  258.  
  259.       if (var2 == -1 && var1.length() == 0) {
  260.          return null;
  261.       } else {
  262.          return var1.toString();
  263.       }
  264.    }
  265.  
  266.    public final String readUTF() throws IOException {
  267.       return DataInputStream.readUTF(this);
  268.    }
  269.  
  270.    public final void writeBoolean(boolean var1) throws IOException {
  271.       this.write(var1 ? 1 : 0);
  272.    }
  273.  
  274.    public final void writeByte(int var1) throws IOException {
  275.       this.write(var1);
  276.    }
  277.  
  278.    public final void writeShort(int var1) throws IOException {
  279.       this.write(var1 >>> 8 & 255);
  280.       this.write(var1 >>> 0 & 255);
  281.    }
  282.  
  283.    public final void writeChar(int var1) throws IOException {
  284.       this.write(var1 >>> 8 & 255);
  285.       this.write(var1 >>> 0 & 255);
  286.    }
  287.  
  288.    public final void writeInt(int var1) throws IOException {
  289.       this.write(var1 >>> 24 & 255);
  290.       this.write(var1 >>> 16 & 255);
  291.       this.write(var1 >>> 8 & 255);
  292.       this.write(var1 >>> 0 & 255);
  293.    }
  294.  
  295.    public final void writeLong(long var1) throws IOException {
  296.       this.write((int)(var1 >>> 56) & 255);
  297.       this.write((int)(var1 >>> 48) & 255);
  298.       this.write((int)(var1 >>> 40) & 255);
  299.       this.write((int)(var1 >>> 32) & 255);
  300.       this.write((int)(var1 >>> 24) & 255);
  301.       this.write((int)(var1 >>> 16) & 255);
  302.       this.write((int)(var1 >>> 8) & 255);
  303.       this.write((int)(var1 >>> 0) & 255);
  304.    }
  305.  
  306.    public final void writeFloat(float var1) throws IOException {
  307.       this.writeInt(Float.floatToIntBits(var1));
  308.    }
  309.  
  310.    public final void writeDouble(double var1) throws IOException {
  311.       this.writeLong(Double.doubleToLongBits(var1));
  312.    }
  313.  
  314.    public final void writeBytes(String var1) throws IOException {
  315.       int var2 = var1.length();
  316.       byte[] var3 = new byte[var2];
  317.       var1.getBytes(0, var2, var3, 0);
  318.       this.writeBytes(var3, 0, var2);
  319.    }
  320.  
  321.    public final void writeChars(String var1) throws IOException {
  322.       int var2 = var1.length();
  323.       int var3 = 2 * var2;
  324.       byte[] var4 = new byte[var3];
  325.       char[] var5 = new char[var2];
  326.       var1.getChars(0, var2, var5, 0);
  327.       int var6 = 0;
  328.  
  329.       for(int var7 = 0; var6 < var2; ++var6) {
  330.          var4[var7++] = (byte)(var5[var6] >>> 8);
  331.          var4[var7++] = (byte)(var5[var6] >>> 0);
  332.       }
  333.  
  334.       this.writeBytes(var4, 0, var3);
  335.    }
  336.  
  337.    public final void writeUTF(String var1) throws IOException {
  338.       DataOutputStream.writeUTF(var1, this);
  339.    }
  340.  
  341.    private static native void initIDs();
  342.  
  343.    private native void close0() throws IOException;
  344.  
  345.    static {
  346.       initIDs();
  347.    }
  348. }
  349.